var express = require('express');
var router = express.Router();

// session  加强的cookies

router.get('/setSession', (req, res) => {
    //登陆之后，要能够快速获取user得姓名，vip等级，是否登录
    req.session.isLogin = "true";
    req.session.userName = "asyAdmin";
    req.session.vipLevel = 5;
    // 重置有效期
    // req.session.cookie.maxAge = 10000;

    res.send('登录状态以设置到session中')
})

router.get('/getSession', (req, res) => {
    if (req.session.isLogin == 'true') {
        res.send("欢迎等级为" + req.session.vipLevel + '的' + req.session.userName + "<a href = '/mySession/exitSession'>退出</a>")
    } else {
        res.send("尚未登录")
    }
})

// 销毁session 的路由

router.get('/exitSession', (req, res) => {
    req.session.destroy(() => {
        console.log('销毁完毕')
    })
    res.send('成功退出登录')
})


module.exports = router;